<?php
/**
 * 车展级别或巡展类别
 * @author qianxun
 *
 */
class carLevelModel extends MY_Model{
    var $typeCon = array(
        1 => '车展级别',
        2 => '巡展类别',
        3 => '广宣形式',
        4 => '营销活动形式',
    );
    /**
     * 构造函数
     */
    function carLevelModel(){
        parent::MY_Model();
        $this->table = 'CarLevel';
        $this->load->library('Cache');
    }
    /**
     * 包装数据(non-PHPdoc)
     * @see MY_Model::packing()
     */
    function packing($list = array()){
        $status = array(1=>'开启',0=>'关闭');
        //时间单位配置
        $this->CI->load->model('timeUnitModel');
        $timeUnitList = $this->CI->timeUnitModel->getCacheData('timeUnitList');
        foreach ($list as $k => $v){
            $list[$k]['typeStr'] = isset($this->typeCon[$v['type']]) ? $this->typeCon[$v['type']] : '';
            //时间单位
            $list[$k]['timeUnitStr'] = isset($timeUnitList[$v['year']][$v['timeUnit']]) ? $timeUnitList[$v['year']][$v['timeUnit']] : '';
            //状态名称
            $list[$k]['statusStr'] = isset($status[$v['status']]) ? $status[$v['status']] : '';
        }
        return $list;
    }
    /**
     * 获取类型名称
     * @param number $type
     */
    function getTypeName($type){
        return isset($this->typeCon[$type]) ? $this->typeCon[$type] : '';
    }
    /**
     * 生成级别缓存数据
     */
    function createActionCache(){
        $actionList = array();
        $actionActiveList = array();
        $findList = $this->getList(array('id >'=>0), null, null, '', 'orderNum asc,id asc');
        foreach ($findList as $k => $v){
            //所有标准动作列表
            $actionList[$v['id']] = $v;
            //激活的标准动作列表
            if ($v['status']){
                $actionActiveList[$v['type']][$v['year']][$v['timeUnit']][$v['id']] = $v['name'];
            }
        }
        $this->cache->set('carLevelList', $actionList);//缓存所有级别数据
        $this->cache->set('carLevelActiveList', $actionActiveList);//缓存激活级别数据
    }
    /**
     * 获取级别缓存数据
     * @param string $type
     *  actionList：所有标准动作数据
     *  actionActiveList：所有激活的标准动作数据
     * @return mix
     */
    function getCacheData($type){
        $this->cache->expire = 86400;//设置过期时间为一天
        $data = $this->cache->get($type);
        if (!$data){
            //创建缓存
            $this->createActionCache();
            $data = $this->cache->get($type);
        }
        return $data;
    }
}